package com.tbit.main.service.impl;

import com.tbit.main.constant.DaoParamConstant;
import com.tbit.main.dao.data.SmartPowerDao;
import com.tbit.main.pojo.MachineStatus;
import com.tbit.main.pojo.Point;
import com.tbit.main.pojo.SmartPower;
import com.tbit.main.service.SmartPowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author LMY
 * @create 2021-01-15 14:05
 * 智能换电
 */
@Service("smartPowerService")
public class SmartPowerServiceImpl implements SmartPowerService {

    @Autowired
    private SmartPowerDao smartPowerDao;

    @Override
    public List<SmartPower> getByAccountId(Integer accountId, String startDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put(DaoParamConstant.accountId, accountId);
        map.put("startDate", startDate);
        map.put("endDate", endDate);
        return smartPowerDao.getByAccountId(map);
    }

    @Override
    public Boolean checkInMachineStatus(MachineStatus machineStatus, List<Point> points, Integer radius) {

        Double area = 0.00001D * radius;

        Double minLo = machineStatus.getLon() - area;
        Double maxLo = machineStatus.getLon() + area;
        Double minLa = machineStatus.getLatC() - area;
        Double maxLa = machineStatus.getLatC() + area;

        for (Point point : points) {
            if (minLo < point.getX() && point.getX() < maxLo &&
                    minLa < point.getY() && point.getY() < maxLa) {
                return true;
            }
        }
        return false;
    }
}
